﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace QLHPHP
{
    public partial class ThemNganhControl : UserControl
    {
        public ThemNganhControl()
        {
            InitializeComponent();
        }

        private AppCommands _Commands;

        /// <summary>
        /// Gets or sets the commands associated with the control.
        /// </summary>
        public AppCommands Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    AppCommands oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }
        /// <summary>
        /// Called when Commands property has changed.
        /// </summary>
        /// <param name="oldValue">Old property value</param>
        /// <param name="newValue">New property value</param>
        protected virtual void OnCommandsChanged(AppCommands oldValue, AppCommands newValue)
        {
            if (newValue != null)
            {
                //buttonDong.Command = newValue.ThemKhoaCommands.Cancel;
                buttonDong.Command = newValue.ThemNganhCommands.Cancel;
            }
            else
            {
                buttonDong.Command = null;
                //buttonDong.Command = null;

            }
        }
        // Load list khoa vao cbbKhoa2
        private void LoadListKhoaInCbb2()
        {
            try
            {
                cbbKhoa2.DataSource = Khoa.LayDsKhoa();
                cbbKhoa2.ValueMember = "MaKhoa";
                cbbKhoa2.DisplayMember = "TenKhoa";
            }
            catch
            {
                MessageBox.Show("Có lỗi trong quá trình lấy dữ liệu, chương trình sẽ thoát!", "Lỗi",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }

        private void ThemNganhControl_Load(object sender, EventArgs e)
        {
            LoadListKhoaInCbb2();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            string id = txtMaNganh.Text;
            string name = txtTenNganh.Text;
            string MaKhoa = cbbKhoa2.SelectedValue.ToString();
            if (id != "" && name != "" && MaKhoa != "")
            {
                
                    try
                    {
                        Nganh.ThemNganh(id, name, MaKhoa);
                        ToastNotification.Show(this, "Thêm Ngành Thành Công!");
                    }
                    catch (Exception ex)
                    {
                        ToastNotification.Show(this, "Mã ngành hoặc Tên ngành đã tồn tại!.");
                    }

               
            }
            else 
            {
                ToastNotification.Show(this, "Vui lòng nhập đủ các trường!");
            }
                
        }
        


    }
}
